﻿using System;
using System.Collections.Generic;
using System.Text;

namespace AX.WCLib.JQuery
{
    public class ToolBar
    {
        private List<ToolItem> arrLst = null;
        //private int _ToolBarHeight = 0;
        private string _Render_Object;

        public ToolBar()
        {
            arrLst = new List<ToolItem>();
            _Render_Object = "body";
        }

        public void Add(ToolItem item)
        {
            arrLst.Add(item);
        }

        public string Render_Object
        {
            get
            {
                return _Render_Object;
            }
            set
            {
                _Render_Object = value;
            }
        }

        public string GetToolBar()
        {
            if (arrLst.Count <= 0) return "";
            string strScpt = "";
            //strScpt = "var toolbar;";
            strScpt = "$(document).ready(function(){";
            strScpt += "    var toolbar = new Toolbar({";
            strScpt += "        renderTo : '" + _Render_Object + "',";

            strScpt += "        items : [";
            string strItms = "";
            foreach (ToolItem itm in arrLst)
            {
                if (strItms.Trim() != "")
                {
                    strItms += ",'-',";
                }
                strItms += "      {type : '" + itm.Type + "',";
                strItms += "      text : '" + itm.Text + "',";
                strItms += "      bodyStyle : '" + itm.BodyStyle + "',";
                if (itm.Useable)
                {
                    strItms += "      useable : 'T',";
                }
                else
                {
                    strItms += "      useable : 'F',";
                }
                strItms += "      handler : function(){";
                strItms += "           " + itm.handler;
                strItms += "      }";
                strItms += "   }";
            }
            if (strItms.Trim() != "")
            {
                strItms += "]";
            }
            strScpt+=strItms+" });";

            strScpt += "     toolbar.render();";
            strScpt += " })";
            return strScpt;
        }
    }

    public class ToolItem
    {
        private string _Text;
        private string _Type;
        private string _BodyStyle;
        private bool _Useable;
        private string _handler;

        public ToolItem()
        {
            _Text = "";
            _Type = "button";
            _BodyStyle = "new";
            _Useable = true;
            _handler = "";

        }

        #region 公共属性
        public string Text
        {
            get
            {
                return _Text;
            }
            set
            {
                _Text = value;
            }
        }

        public string Type
        {
            get
            {
                return _Type;
            }
            set
            {
                _Type = value;
            }
        }

        public string BodyStyle
        {
            get
            {
                return _BodyStyle;
            }
            set
            {
                _BodyStyle = value;
            }
        }

        public bool Useable
        {
            get
            {
                return _Useable;
            }
            set
            {
                _Useable = value;
            }
        }

        public string handler
        {
            get
            {
                return _handler;
            }
            set
            {
                _handler = value;
            }
        }

        #endregion

    }
}
